﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Collections;
using System.Collections.Generic;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Linq;

namespace JavaSubstitutes
{
	public static class UIElementCollectionExtensions
	{

		///// <summary>
		///// Removes ALL items of a certain type. For example- removing all buttons:
		///// LayoutRoot.Children.RemoveType(typeof(Button));
		///// </summary>
		///// <param name="children">Collection to remove items from</param>
		///// <param name="typeToRemove">Type to remove from the collection</param>
		//public static void RemoveType(this UIElementCollection children, System.Type typeToRemove)
		//{
		//    //not sure why this dosen't work...
		//    //List<UIElement> elements = (from UIElement element in children where typeof(element) is typeToRemove select element).ToList();
		//    for(int i=0; i<children.Count; i++)
		//    {
		//        //if(!(typeof(children[i]) is typeToRemove) continue;
		//        //Type t = typeof(children.Item[i]);
		//        if (!(children[i].GetType() == typeToRemove)) continue;

		//        children.RemoveAt(i);
		//        i--;
		//    }
		//}


		/// <summary>
		/// Removes all BUT items of a certain type. For example- removing all buttons:
		/// LayoutRoot.Children.RemoveType(typeof(Button));
		/// </summary>
		/// <param name="children">Collection to remove items from</param>
		/// <param name="typeToRemove">Type to remove from the collection</param>
		public static void RemoveAllButType(this UIElementCollection children, System.Type typeToRemove)
		{
			//not sure why this dosen't work...
			//List<UIElement> elements = (from UIElement element in children where typeof(element) is typeToRemove select element).ToList();
			for (int i = 0; i < children.Count; i++)
			{
				//if(!(typeof(children[i]) is typeToRemove) continue;
				//Type t = typeof(children.Item[i]);
				if ((children[i].GetType() == typeToRemove)) continue;

				children.RemoveAt(i);
				i--;
			}
		}


	}
}
